package com.rf.richfitwheel.admin.sys.controller;

import com.rf.richfitwheel.admin.annotation.UserOperateLog;
import com.rf.richfitwheel.admin.contants.UrlConstant;
import com.rf.richfitwheel.admin.sys.model.Vacation;
import com.rf.richfitwheel.admin.sys.service.VacationService;
import com.rf.richfitwheel.admin.sys.vo.UserVO;
import com.rf.richfitwheel.admin.utils.UserUtil;
import com.rf.richfitwheel.common.utils.PageUtils;
import com.rf.richfitwheel.common.utils.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping(UrlConstant.WEB_ADMIN_URL + "/vacation")
public class VacationController {
    @Autowired
    private VacationService vacationService;

    /**
     * 查询模型列表
     *
     * @param params
     * @return
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        UserVO user = UserUtil.getUser();
        PageUtils pageUtil = vacationService.list(params, user);
        return R.ok().put("page", pageUtil);
    }

    /**
     * 保存岗位数据
     *
     * @param vacation
     * @return
     */
    @UserOperateLog(module = "系统功能", methods = "save", description = "保存岗位数据信息")
    @PostMapping("/save")
    public R save(@RequestBody Vacation vacation) {

        if (vacation.getId() == null || "".equals(vacation.getId())) {
            //新增
            vacationService.addVacation(vacation, UserUtil.getUser());
        } else {
            //修改
            vacationService.updateVacation(vacation, UserUtil.getUser());
        }
        return R.ok();
    }

    /**
     * 根据用户ID获取用户所有岗位信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getVacationById/{id}")
    public R getVacationById(@PathVariable("id") String id) {
        Vacation vacation = vacationService.getVacationById(id);
        return R.ok().put("vacation", vacation);
    }

    /**
     * @param params
     * @return
     */
    @UserOperateLog(module = "系统功能", methods = "save", description = "保存岗位数据信息")
    @PostMapping("/temp")
    public R temp(@RequestBody Map<String, Object> params) {
        UserVO user = UserUtil.getUser();
        vacationService.temp(params, UserUtil.getUser());
        return R.ok();
    }

    /**
     * @param params
     * @return
     */
    @UserOperateLog(module = "系统功能", methods = "save", description = "保存岗位数据信息")
    @PostMapping("/addAndSubmit")
    public R addAndSubmit(@RequestBody Map<String, Object> params) {
        UserVO user = UserUtil.getUser();
        vacationService.addAndSubmitVacation(params, UserUtil.getUser());

        return R.ok();
    }

    @UserOperateLog(module = "系统功能", methods = "save", description = "保存岗位数据信息")
    @PostMapping("/updateAndSubmit")
    public R updateAndSubmit(@RequestBody Map<String, Object> params) {
        UserVO user = UserUtil.getUser();
        vacationService.updateAndSubmitVacation(params, user);

        return R.ok();
    }
}
